from typing import Any, List, Dict
from matcher import Matcher
from scheduler import Scheduler
from global_var import alpha, gamma1, gamma2
import random


class Agent:
    def __init__(self):
        self.matcher = Matcher(alpha, gamma1)
        self.scheduler = Scheduler(gamma2)

    def dispatch(self, dispatch_observ: List[Dict[str, Any]]) -> List[Dict[str, str]]:
        """
        在每个time step计算司机乘客的分配对
        :param dispatch_observ:
        order_id,               订单ID
        driver_id,              司机ID
        order_driver_distance,  订单和司机的距离
        order_start_location,   订单开始距离
        order_finish_location,  订单结束距离
        driver_location,        司机位置
        timestamp,              时间戳
        order_finish_timestamp, 订单结束时间戳
        day_of_week,            星期几
        reward_units,           回报
        pick_up_eta,            拒单率

        :return: a list of dict
        [{order_id, driver_id}, {...}]
        """
        return self.matcher.dispatch(dispatch_observ)

    def reposition(self, repo_observ: Dict[str, Any]) -> List[Dict[str, str]]:
        """
        对给定的司机，进行车辆调度
        :param repo_observ:
        timestamp: int
        driver_info: a list of dict, the key in the dict includes:
            driver_id: driver_id of the idle driver in the treatment group, int
            grid_id: id of the grid the driver is located at, str
        day_of_week: int
        :return:
        driver_id: corresponding to the driver_id in the od_list
        destination: id of the grid the driver is repositioned to, str
        """
        return self.scheduler.reposition(self.matcher, repo_observ)
